//
//  RTToastManager.m
//  RtMart
//
//  Created by 福利购Mac on 16/12/1.
//  Copyright © 2016年 JASON. All rights reserved.
//

#import "RTToastManager.h"
#import "AppDelegate.h"
#import <MBProgressHUD.h>

static RTToastManager *toastManager;

@implementation RTToastManager
#pragma mark -manager
+ (RTToastManager *)ShardInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        toastManager = [[RTToastManager alloc] init];
    });
    return toastManager;
}
- (void)showProgress:(UIView*)view{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.backgroundColor = [UIColor whiteColor];
    UIImageView *gifImageView = [[UIImageView alloc] init];
    NSMutableArray * images = [NSMutableArray array];
    for (int index = 0; index< 0; index++) {
        NSString * imageName = [NSString stringWithFormat:@"loading%d.png",index];
        UIImage *image = [UIImage imageNamed:imageName];
        [images addObject:image];
    }
    gifImageView.animationImages = images;
    gifImageView.animationDuration = 1.65;
    [gifImageView startAnimating];
    hud.customView = gifImageView;
    hud.bezelView.backgroundColor = [UIColor whiteColor];
}

- (void)showToast:(NSString *)toastStr{
    UIWindow *keywindow = [RTToastManager keyWindow];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:keywindow animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = NSLocalizedString(toastStr, @"HUD message title");
    hud.label.numberOfLines = 0;
    hud.offset = CGPointMake(0.0f, 0.0f);
    [hud hideAnimated:YES afterDelay:1.5f];
}
- (void)showToast:(NSString *)toastStr wait:(float)wait{
    UIWindow *keywindow = [RTToastManager keyWindow];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:keywindow animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = NSLocalizedString(toastStr, @"HUD message title");
    hud.label.numberOfLines = 0;
    hud.offset = CGPointMake(0.0f, 0.0f);
    [hud hideAnimated:YES afterDelay:wait];
}
- (void)hideProgress:(UIView*)view{
    [MBProgressHUD hideHUDForView:view animated:YES];
}

- (void)showHUD:(HUDShowType)type{

}
#pragma mark -keyWindow
+ (UIWindow *)keyWindow {
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    UIWindow *keywindow = delegate.window;
    return keywindow;
}
@end
